package com.xgj.config;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

//spring-boot-admin :管理springboot应用的，里面带了管理Quartz Scheduler的ui
//http://192.168.31.170:9999/instances/64c843610983/quartz
@Component
@Endpoint(id = "quartz-status")
public class QuartzStatusEndpoint {

    @Autowired
    private Scheduler scheduler;

    @ReadOperation
    public Map<String, Object> getQuartzStatus() throws SchedulerException {
        Map<String, Object> status = new HashMap<>();
        status.put("isStarted", scheduler.isStarted());
        status.put("isInStandbyMode", scheduler.isInStandbyMode());
        status.put("isShutdown", scheduler.isShutdown());
        // 可以添加更多的 Quartz 状态信息
        return status;
    }
}
